import 'package:geolocator/geolocator.dart';
import 'package:xsdk_flutter/xsdk/utils/x_utils_log.dart';
/*
获得定位 (location,background_location,实测没返回,不可用):

geolocator 更活跃的维护
https://pub-web.flutter-io.cn/packages/geolocator
dependencies:
  geolocator: ^13.0.2

import 'package:geolocator/geolocator.dart';

 */
abstract class XLocationUtils{


  //获得当前位置经纬度
  static getCurrentLocation() async{

    bool serviceEnabled = await Geolocator.isLocationServiceEnabled();
    if (!serviceEnabled) {
      XLogUtils.printLog('---serviceEnabled false');
      return;
    }

    LocationPermission permission = await Geolocator.checkPermission();
    if (permission == LocationPermission.denied) {
      permission = await Geolocator.requestPermission();
      if (permission == LocationPermission.denied) {
        XLogUtils.printLog('---LocationPermission false');
        return;
      }
    }

    if (permission == LocationPermission.deniedForever) {
      XLogUtils.printLog('---LocationPermission deniedForever');
      return;
    }

    // When we reach here, permissions are granted and we can
    // continue accessing the position of the device.
    XLogUtils.printLog('---start getCurrentPosition');
    Position positionData= await Geolocator.getCurrentPosition();
    //实测只有经纬度有返回值
    XLogUtils.printLog('---positionData=纬度:${positionData.latitude},经度=${positionData.longitude}');

  }



}
